package com.base.game;

import com.base.engine.*;

public class Flashlight 
{
	/* Light Constans */
	private final float radioDeLuz = 0.3f; // A mayor, menor el radio
	private final float lightColor = 0.9f;
	private final float intensidad = 2.4f;
	private final float radioDeDifuminado = 9f;
	private final float tamanoRadioLinterna = 0.50f; // 0.88
	private final float crazyLightEffect = 1; // en -1 crea un efecto todo loco
	
	private boolean lightsOn = true;
	
	private SpotLight sl;
	private PointLight pl;
	private SoundEffect soundEffect;
	
	public Flashlight(BaseLight base, Attenuation att, Camera cam, float difuminationRadius)
	{
		pl = new PointLight(base, att, cam.getPos(), difuminationRadius);
		sl = new SpotLight(pl, cam.getForward(), tamanoRadioLinterna);		
	}
	
	public Flashlight(Camera cam)
	{
		pl = new PointLight(new BaseLight(new Vector3f(lightColor, lightColor, lightColor), intensidad), 
							new Attenuation(crazyLightEffect, 0, radioDeLuz), 
							cam.getPos(), radioDeDifuminado); 
		
		sl = new SpotLight(pl, cam.getForward(), tamanoRadioLinterna);	
		
		PhongShader.setSpotLights(new SpotLight[]{ sl });
		
		soundEffect = new SoundEffect("OGG", "flashlightClick.ogg");
	}
	
	public void turnLights()
	{		
		soundEffect.play();		
		
		if (lightsOn)		
			pl.setBaseLight(new BaseLight(new Vector3f(0,0,0), 0));		
		else		
			pl.setBaseLight(new BaseLight(new Vector3f(lightColor, lightColor, lightColor), intensidad));
		lightsOn = !lightsOn;
	}
	
	public void update()
	{
		pl.setPosition(Transform.getCamera().getPos());		
		sl.setPointLight(pl);
		sl.setDirection(Transform.getCamera().getForward());
	}
}
